package com.canaan.business.controller.pc.basic;

import java.util.List;

import com.canaan.common.config.RuoYiConfig;
import com.canaan.common.utils.StringUtils;
import com.canaan.common.utils.file.FileUploadUtils;
import com.canaan.common.utils.file.MimeTypeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.basic.StorehouseLocationPlat;
import com.canaan.business.service.basic.IStorehouseLocationPlatService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 库位绘制地图信息Controller
 *
 * @author 
 * @date 2023-08-04
 */
@Api(tags = "库位绘制地图信息")
@RestController
@RequestMapping("/basic/storehouseLocationPlat")
public class StorehouseLocationPlatController extends BaseController {
    @Resource
    private IStorehouseLocationPlatService storehouseLocationPlatService;

    /**
     * 查询库位绘制地图信息列表
     */
    @ApiOperation(value = "查询库位绘制地图信息列表")
    @GetMapping("/list")
    public TableDataInfo list(StorehouseLocationPlat storehouseLocationPlat) {
        startPage();
        List<StorehouseLocationPlat> list = storehouseLocationPlatService.selectStorehouseLocationPlatList(storehouseLocationPlat);
        return getDataTable(list);
    }

    /**
     * 导出库位绘制地图信息列表
     */
    @ApiOperation(value = "导出库位绘制地图信息列表")
    @Log(title = "库位绘制地图信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StorehouseLocationPlat storehouseLocationPlat) {
        List<StorehouseLocationPlat> list = storehouseLocationPlatService.selectStorehouseLocationPlatList(storehouseLocationPlat);
        ExcelUtil<StorehouseLocationPlat> util = new ExcelUtil<StorehouseLocationPlat>(StorehouseLocationPlat.class);
        util.exportExcel(response, list, "库位绘制地图信息数据");
    }

    /**
     * 获取库位绘制地图信息详细信息
     */
    @ApiOperation(value = "获取库位绘制地图信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(storehouseLocationPlatService.selectStorehouseLocationPlatById(id));
    }
    @ApiOperation(value = "获取库位绘制地图信息详细信息")
    @GetMapping(value = "/getInfoByStorehouseLocationNo/{storehouseLocationNo}")
    public AjaxResult getInfoByStorehouseLocationNo(@PathVariable("storehouseLocationNo")  String storehouseLocationNo){
        return success(storehouseLocationPlatService.getInfoByStorehouseLocationNo(storehouseLocationNo));
    }

    /**
     * 新增库位绘制地图信息
     */
    @ApiOperation(value = "新增库位绘制地图信息")
    @Log(title = "库位绘制地图信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StorehouseLocationPlat storehouseLocationPlat) {
        return toAjax(storehouseLocationPlatService.insertStorehouseLocationPlat(storehouseLocationPlat));
    }

    /**
     * 修改库位绘制地图信息
     */
    @ApiOperation(value = "修改库位绘制地图信息")
    @Log(title = "库位绘制地图信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StorehouseLocationPlat storehouseLocationPlat) {
        return toAjax(storehouseLocationPlatService.updateStorehouseLocationPlat(storehouseLocationPlat));
    }

    /**
     * 删除库位绘制地图信息
     */
    @ApiOperation(value = "删除库位绘制地图信息")
    @Log(title = "库位绘制地图信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(storehouseLocationPlatService.deleteStorehouseLocationPlatByIds(ids));
    }

    /**
     * 库位图片上传
     */
    @Log(title = "库位图片上传", businessType = BusinessType.UPDATE)
    @PostMapping("/uploadStoreHouseLocation")
    public AjaxResult uploadStoreHouseLocation(@RequestParam("storeHouseLocationfile") MultipartFile file, @RequestParam("storeHouseLocationNo") String storeHouseLocationNo) throws Exception
    {
        if (!file.isEmpty())
        {
            String url = FileUploadUtils.upload(RuoYiConfig.getStoreHouseLoactionPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
            if (StringUtils.isNotEmpty(storeHouseLocationNo)){
                storehouseLocationPlatService.uploadStoreHouseLocation(storeHouseLocationNo,url);
            }
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", url);
            return ajax;
        }
        return error("上传图片异常，请联系管理员");
    }
}
